/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: jse2204 - T7
 * <p>Powered by webrx On 2022-09-30 16:17:24
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T7 {
    static class Demo {
        private Object o = new Object();

        public void a() {
            String t = Thread.currentThread().getName();
            System.out.println(t + ".....");
            synchronized (o) {
                try {
                    TimeUnit.SECONDS.sleep(5);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println(t);
                System.out.println("a()....");
            }
        }

        public void b() {
            String t = Thread.currentThread().getName();
            System.out.println(t + ".....");
            synchronized (o) {
                try {
                    TimeUnit.SECONDS.sleep(5);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println(t);
                System.out.println("b()...");
            }
        }
    }

    public static void main(String[] args) {
        Demo d = new Demo();

        new Thread(d::a, "t1").start();
        new Thread(d::b, "t2").start();

    }
}
